package com.spzx.product.api.factory;

import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.api.RemoteProductService;
import com.spzx.product.api.domain.vo.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public class RemoteProductFallbackFactory implements FallbackFactory<RemoteProductService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteProductFallbackFactory.class);
    @Override
    public RemoteProductService create(Throwable cause) {
        log.error("商品服务调用失败：{}",cause.getMessage());
        return new RemoteProductService() {
            @Override
            public R<List<ProductSku>> getTopSale(String source) {
                System.out.println("发生异常，调用降级方法：getTopSale()");
                return null;
            }

            @Override
            public R<TableDataInfo> skuList(Integer pageNum, Integer pageSize, SkuQuery skuQuery, String source) {
                return R.fail("获取商品列表失败:" + cause.getMessage());
            }

            @Override
            public R<ProductSku> getProductSku(Long skuId, String source) {
                System.out.println("发生异常，调用降级方法：getProductSku()");

                return null;
            }

            @Override
            public R<Product> getProduct(Long id, String source) {
                System.out.println("发生异常，调用降级方法：getProduct()");

                return null;
            }

            @Override
            public R<SkuPrice> getSkuPrice(Long skuId, String source) {
                System.out.println("发生异常，调用降级方法：getSkuPrice()");

                return null;
            }

            @Override
            public R<ProductDetails> getProductDetails(Long productId, String source) {
                System.out.println("发生异常，调用降级方法：getProductDetails()");

                return null;
            }

            @Override
            public R<Map<String, Long>> getSkuSpecValue(Long productId, String source) {
                System.out.println("发生异常，调用降级方法：getSkuSpecValue()");

                return null;
            }

            @Override
            public R<SkuStockVo> getSkuStock(Long skuId, String source) {
                System.out.println("发生异常，调用降级方法：getSkuStock()");

                return null;
            }

            @Override
            public R<List<SkuPrice>> getSkuPriceList(List<Long> skuIds, String inner) {
                System.out.println("发生异常，调用降级方法：getSkuPriceList()");
                return null;
            }

            @Override
            public R<String> checkAndLock(String OrderNo, List<SkuLockVo> skuLockVoList, String source) {
                System.out.println("发生异常，调用降级方法：checkAndLock()");
                return null;
            }


        };
    }
}
